﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


using Actuals.CoreDomain;
using Actuals.Common;
using Actuals.Business;
using Actuals.CoreDomain.Business;
using Actuals.CoreDomain.Data;
using System.Data;

namespace Actuals
{
    public partial class ShowPublicHolidays : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.AddHeader("Cache-control", "no-store, must-revalidate,private,no-cache");
            Response.AddHeader("Pragma", "no-cache");
            Response.AddHeader("Expires", "0");

            Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);


            if (Session["EmployeeId"] == null)
            {
                Response.Write("Please Login!");
                Response.End();
            }
           

           
                if (Request.Form["__EVENTTARGET"] == "refresh")
                {
                    BindGridView();
                }
          
        }



        protected void BindGridView()
        {
            int year = int.Parse(ddlYear.SelectedValue.ToString());
            IBusinessPublicHoliday businessPublicHoliday = new BusinessPublicHoliday();
            IList<IPublicHoliday> publicHolidays = businessPublicHoliday.GetPubHolidays(year);
            ViewState["DataSource"] = publicHolidays;
            gvResults.DataSource = publicHolidays;
            gvResults.DataBind();

        }
        protected void btnGetPublicHolidays_Click(object sender, EventArgs e)
        {
            BindGridView();
        }
        protected void gvResults_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string id;
            switch (e.CommandName)
            {
                case "EditPublicHolidays":
                    id = e.CommandArgument.ToString();
                    ClientScript.RegisterStartupScript(this.GetType(), "ShowUpdatePublicHolidays", "ShowUpdatePublicHolidays('" + id + "')", true);
                    break;
            }

        }
        protected void btn_DeletePublicHolidays(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < gvResults.Rows.Count; i++)
                {
                    CheckBox cb = (CheckBox)gvResults.Rows[i].FindControl("chkShowPublicHolidays");
                    Label lbl = (Label)gvResults.Rows[i].FindControl("lblId");

                    if (cb.Checked)
                    {
                        string id = string.Empty;
                        if (lbl != null)
                        {
                            id = lbl.Text;
                            IBusinessPublicHoliday businessPublicHoliday = new BusinessPublicHoliday();
                            businessPublicHoliday.DeletePublicHolidays(int.Parse(id));

                        }
                    }
                }
                lblMsg.Text = "Deleted";
                BindGridView();
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }
        }






    }
}